﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Common.Utilities.OpenXml;
using Workflows.Components.Reports.Properties;

namespace Workflows.Components.Reports.OpenXmlUtil
{
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public class Excel2007ReportComponent:WorkflowComponentBase
	{
		/// <summary>
		/// 
		/// </summary>
		public Excel2007ReportComponent():base()
		{
			this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
			this.ComponentCategory = WorkflowComponentCategory.Report_Tasks.ToString();
			this.ComponentIcon = Resources.Microsoft_1_201;
			this.ComponentImage = Resources.Microsoft_202;
			this.ComponentName = "Excel 2007 Report";
			this.Description = "Define excel report template and data bindings using sql select statement";

			this._Instruction = new Excel2007ReportInstruction(
				this.ComponentID, Guid.Empty, string.Empty, string.Empty,
				new List<TableDataFromSql>(), 
				new Dictionary<string, WorksheetTableBinding>(),
				new Dictionary<string, ChartDefinition>());
			this._Output = new Excel2007ReportOutput(this.ComponentID, Guid.Empty, string.Empty);
		}

		#region Overrides of WorkflowComponentBase

		private Excel2007ReportInstruction _Instruction;
		/// <summary>an object that encapsulate instruction settings.</summary>
		public override InstructionBase Instruction
		{
			get { return _Instruction; }
			set { _Instruction=(Excel2007ReportInstruction)value; }
		}

		private Excel2007ReportOutput _Output;
		/// <summary>an object to encapsulate output</summary>
		public override ResultBase Output
		{
			get { return _Output; }
			set { _Output = (Excel2007ReportOutput) value; }
		}

		#endregion

		#region xml 
		public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
		{
			XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
			this.Instruction.Serialize(ref xDoc, ref xNode);
			return xNode;
		}

		public override WorkflowComponentBase Instantiate(XmlNode xNode)
		{
			Excel2007ReportComponent component = (Excel2007ReportComponent)base.Instantiate(xNode);
			component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
			return component;
		}
		#endregion
	}
}
